<?php date_default_timezone_set ('Asia/Shanghai');

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(dirname(__FILE__)  . '/library'),
    realpath(dirname(__FILE__)  . '/include'),
    get_include_path(),
)));

require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);

// load the application configuration
$config = new Zend_Config_Ini ( './include/configs/settings.ini', 'development' );
Zend_Registry::set ( 'config', $config );

// create the application logger
$logger = new Zend_Log(new Zend_Log_Writer_Stream($config->logging->file));
Zend_Registry::set('logger', $logger);

// connect to the database
$params = array ('host' => $config->database->hostname, 
                 'username' => $config->database->username, 
                 'password' => $config->database->password, 
                 'dbname' => $config->database->database );

$db = Zend_Db::factory ( $config->database->type, $params );
Zend_Registry::set ( 'db', $db );

// setup application authentication
$auth = Zend_Auth::getInstance ();
$auth->setStorage ( new Zend_Auth_Storage_Session () );

// handle the user request
$controller = Zend_Controller_Front::getInstance ();
$controller->setControllerDirectory ( $config->path->base . '/include/controllers' );

// setup the view renderer
$vr = new Zend_Controller_Action_Helper_ViewRenderer();
$vr->setView(new Templater());
$vr->setViewSuffix('tpl');
Zend_Controller_Action_HelperBroker::addHelper($vr);
$controller->dispatch ();

?>